package com.company.test19;

import com.sun.xml.internal.ws.policy.privateutil.PolicyUtils;
import org.omg.Messaging.SYNC_WITH_TRANSPORT;

import java.io.*;

/**
 * Created by Administrator on 2016.9.23.
 */
public class Test1910 {
    public static void main(String[] args) throws IOException{
        File[] files=new File[5];
        File file=new File("src/com/company/test19/01.001");

        DataInputStream bigFile=new DataInputStream(new FileInputStream(file));

        long sign=file.length()/5;
        for(int i=0;i<4;i++){
            System.out.println(sign);
            files[i]=new File("src/com/company/test19/"+i);
            files[i].createNewFile();

            DataOutputStream output=new DataOutputStream(new BufferedOutputStream(new FileOutputStream(files[i])));
            for (long j=0;j<=sign;j=j+1000){
                byte[] bytes=new byte[1000];
                bigFile.read(bytes,0,1000);
                output.write(bytes);
            }
            output.close();
        }
        files[4]=new File("src/com/company/test19/4");
        files[4].createNewFile();
        DataOutputStream output=new DataOutputStream(new BufferedOutputStream(new FileOutputStream(files[4])));
        for (long i=0;i<=file.length()-(sign/1000+1)*4000;i=i+1000){
            if(i+1000<=file.length()-(sign/1000+1)*4000){
                byte[] bytes=new byte[1000];
                bigFile.read(bytes,0,1000);
                output.write(bytes);
            }else {
                try {
                    while (true){
                        output.write(bigFile.readByte());
                        i++;
                    }
                }catch (EOFException e){
                    break;
                }
            }
        }
        output.close();
        bigFile.close();
    }
}